<script>
layui.use('table', function(){
  var table = layui.table;
  
	table.render({
	    elem: '#test'
	    ,url:'/data/list/{{.Mid}}'
	    ,toolbar: '#toolbarDemo'
	    ,cellMinWidth: 60 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
	    ,cols: [[
	      	{field:'did', title: 'ID', sort: true}
	      	,{field:'name', title: '名称'}
			{{range $k,$v := .Title}}
				,{field:'{{$k}}',title:'{{$v}}'}
			{{end}}
			,{field:'seq', title: '排序(倒序)'}
			,{field:'status', title: '状态'}
			,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
	    ]]
		,page:true
  	});
	


	//头工具栏事件
  	table.on('toolbar(test)', function(obj){
	    switch(obj.event){
		  case 'add':
			layer.open({
				type:2,
				area: ['800px','600px'],
				offset: 'auto',
				title:'添加',
				content:"/data/add/{{.Mid}}"
			});
	      break;
	    };
	});

	//监听行工具事件
  	table.on('tool(test)', function(obj){
	    var data = obj.data;
	    console.log(obj)
	    if(obj.event === 'del'){
	      layer.confirm('真的删除行么', function(index){
			layui.jquery.get("/data/deletedo/{{.Mid}}?did="+data.did);
	        obj.del();
	        layer.close(index);
	      });
	    } else if(obj.event === 'edit'){
			layer.open({
				type:2,
				area: ['800px','600px'],
				offset: 'auto',
				title:'编辑',
				content:"/data/edit/{{.Mid}}?did="+data.did
			});
	    }
	  });
	
});

</script>

